/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.documents.main.action;

import com.documents.common.core.PageBean;
import com.documents.common.core.action.BaseActionSupport;
import com.documents.pojo.Country;
import com.documents.service.country.CountryService;
import java.util.List;
import org.apache.struts2.interceptor.ServletRequestAware;

/**
 *
 * @author sunying
 */
public class CountryAction extends BaseActionSupport implements ServletRequestAware {

    private static final long serialVersionUID = 1003L;
    private CountryService countryService;
    private List<Country> allCountry;
    private Integer pid = 0;
    private String pname;
    private int page=1;
    private PageBean pageBean;
    private int pageSize = 20;
    private Country country;

    private String actionURI;

    public Country getCountry() {
        return country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    public List<Country> getAllCountry() {
        return allCountry;
    }

    public void setAllCountry(List<Country> allCountry) {
        this.allCountry = allCountry;
    }

    public CountryService getCountryService() {
        return countryService;
    }

    public void setCountryService(CountryService countryService) {
        this.countryService = countryService;
    }
       

    public String getActionURI() {
        return this.actionURI;
    }

    public void setActionURI(String actionURI) {
        this.actionURI = actionURI;
    }


    public int getPage() {
        return this.page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public PageBean getPageBean() {
        return this.pageBean;
    }

    public void setPageBean(PageBean pageBean) {
        this.pageBean = pageBean;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPid() {
        return this.pid;
    }

    public void setPid(Integer parentId) {
        this.pid = parentId;
    }

    public String getpName() {
        return this.pname;
    }

    public void setpName(String pName) {
        this.pname = pName;
    }

    public String main() throws Exception {
        return "success";
    }

    public String top() throws Exception {
        this.allCountry = countryService.findAll();
        return "success";
    }

    public String list() throws Exception {

        pageBean = countryService.getPageBean(page, pageSize, country);

        return SUCCESS;
    }
    
     public void deleteById() {
        
        countryService.deleteById(country.getId());
    }

    public String addInput() throws Exception {
        actionURI = "save";
    
        return SUCCESS;
    }

    public String save() throws Exception {
        countryService.saveInstance(country);
        return SUCCESS;
    }
    
     public String update() throws Exception {
        countryService.update(country);
        return SUCCESS;
    }
    
    public String updateInput() throws Exception {
        actionURI = "update";
        country = this.countryService.get(country.getId());
        if(country == null)
            return ERROR;
        else
            return SUCCESS;
    }
    

  
}
